#include<vector>
using namespace std;

class Solution {
public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k) {
        if (k <= 1) return 0;
        int left = 0, right = 0;
        int res = 0;
        int mul = 1;
        for (int right = 0; right < nums.size(); ++right) {
            mul *= nums[right];
            while (mul >= k) mul /= nums[left++];
            res += right - left + 1;

        }
        return res;
    }
};